﻿using System.Net;

namespace Toybox.NicoSharp.Seiga
{
	using Primitives;
	using Utilities;

	public partial class OfficialComic : AbstractResource
	{

		#region Constructor

		public OfficialComic(string id, CookieCollection cookies = null)
			: base(id, cookies)
		{
		}

		public OfficialComic(ContentId contentId, CookieCollection cookies = null)
			: base(contentId, cookies)
		{
		}

		#endregion Constructor


		#region Public Members

		public ContentId FirstId
		{
			get
			{
				if (_firstId == null)
					this._firstId = new ContentId(this.GetFirstUrl());
				return this._firstId;
			}
		}
		private ContentId _firstId;

		public ContentId NewId
		{
			get { return new ContentId(this.GetNewUrl()); }
		}

		#endregion Public Members

		#region Protected Members

		protected virtual string MangaUrl
		{
			get { return NicoUrls.SeigaApi + "manga/"; }
		}

		protected virtual string InfoUrl
		{
			get { return this.MangaUrl + "info?id="; }
		}

		#endregion Protected Members


		#region Public Methods

		public Info GetInfo()
		{
			return this.Get<Info>(this.InfoUrl + this.ContentId.Digits);
		}

		public string GetFirstUrl(bool isRedirect = true)
		{
			string url = NicoUrls.SeigaTop + @"comic/" + this.ContentId.Digits + "/ep1";
			return isRedirect ? NicoWebClient.GetRedirectUrl(url, this.Cookies) : url;
		}

		public string GetNewUrl(bool isRedirect = true)
		{
			string url = NicoUrls.SeigaTop + @"comic/" + this.ContentId.Digits + "/new";
			return isRedirect ? NicoWebClient.GetRedirectUrl(url, this.Cookies) : url;
		}

		#endregion Public Methods

	}
}
